/**
 * used to dynamic load the js files.
 * @author peter
 */

/**
 * _addHostEnv used to store the 
 */
ihelpuoo.env["_addHostEnv"]={
	loadedModules:{}
};

ihelpuoo.getRootPath = function(){
	if(ihelpuoo.env["RootPath"]){
		return ihelpuoo.env["RootPath"];
	}
	//start to caculate the root path
	var scripts = document.getElementsByTagName("script");
	for(var i = 0; i < scripts.length; i++) {
		var src = scripts[i].getAttribute("src");
		if(!src) { continue; }
		var index = src.indexOf("ihelpuoo.js");
		if(index) {
			ihelpuoo.env["RootPath"] = src.substring(0, index)+"../";
			return ihelpuoo.env["RootPath"];
		}
	}
	
}


/**
 * regist the module into env
 * @param {String} sModuleName
 */
ihelpuoo.regist = function(sModuleName){
	if(sModuleName){
		ihelpuoo.env["_addHostEnv"].loadedModules[sModuleName] = sModuleName;
	}
};

/**
 * indecate the required module
 * @param {String} sModuleName
 */
ihelpuoo.require = function(sModuleName){
	if(!sModuleName) return;
	if(ihelpuoo.env["_addHostEnv"].loadedModules[sModuleName]) return;
	ihelpuoo.loadModule(sModuleName);
	ihelpuoo.env["_addHostEnv"].loadedModules[sModuleName] = sModuleName;
};

/**
 * load module
 * @param {String} sModuleName
 */
ihelpuoo.loadModule = function(sModuleName){
	var path = sModuleName.replace(/\./g, '/') + '.js';
	var module = ihelpuoo.http.GETString(ihelpuoo.getRootPath()+path);
	eval(module);
};